package com.crm.service.impl.activityManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.activityManager.CustomerGiftActivityRelationMapper;
import com.crm.model.entity.activityManager.CustomerGiftActivityRelation;
import com.crm.model.entity.activityManager.CustomerGiftActivityRelationExample;
import com.crm.service.activityManager.CustomerGiftActivityRelationDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luojie
 * @date 2021/3/1 14:45
 */
@Service
public class CustomerGiftActivityRelationDbServiceImpl implements CustomerGiftActivityRelationDbService {

    @Autowired
    private CustomerGiftActivityRelationMapper customerGiftActivityRelationMapper;

    @Override
    public Boolean insertCustomerGiftActivityRelation(CustomerGiftActivityRelation customerGiftActivityRelation) {
        Boolean result = false;
        int num = customerGiftActivityRelationMapper.insertSelective(customerGiftActivityRelation);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 赠品列表--(删除赠品-赠品活动关系表设置为删除状态)
     * @param customerGiftActivityRelation ---(赠品活动关系表model)
     * @return
     */
    @Override
    public Boolean deleteCustomerGiftActivityRelationByCustomerGiftActivity(CustomerGiftActivityRelation customerGiftActivityRelation) {
        return customerGiftActivityRelationMapper.updateByPrimaryKeySelective(customerGiftActivityRelation) > 0;
    }

    @Override
    public List<CustomerGiftActivityRelation> selectGiftDropDownCheckedListByGiftActivityId(String giftActivityId) {
        CustomerGiftActivityRelationExample giftActivityRelationExample = new CustomerGiftActivityRelationExample();
        CustomerGiftActivityRelationExample.Criteria criteria = giftActivityRelationExample.createCriteria();
        criteria.andProductGiftActivityIdEqualTo(giftActivityId);
        criteria.andDeleteStatusEqualTo((short) StatusCodeEnum.NORMAL_CODE.getState());
        List<CustomerGiftActivityRelation> customerGiftActivityRelationList= customerGiftActivityRelationMapper.selectByExample(giftActivityRelationExample);
        return customerGiftActivityRelationList;
    }
}
